﻿using System;
using System.Data;
using System.Collections.Generic;
using Royalsoft.Common;
using NJL.Model;
using NJL.DALFactory;
using NJL.IDAL;
namespace NJL.BLL
{
    /// <summary>
    /// NJL_MESSAGES
    /// </summary>
    public partial class NJL_MESSAGES
    {
        private readonly INJL_MESSAGES dal = DataAccess.CreateNJL_MESSAGES();
        public NJL_MESSAGES()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(NJL.Model.NJL_MESSAGES model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(NJL.Model.NJL_MESSAGES model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            return dal.Delete(ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            return dal.DeleteList(IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public NJL.Model.NJL_MESSAGES GetModel(string ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public NJL.Model.NJL_MESSAGES GetModelByCache(string ID)
        {

            string CacheKey = "NJL_MESSAGESModel-" + ID;
            object objModel = Royalsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(ID);
                    if (objModel != null)
                    {
                        int ModelCache = Royalsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Royalsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (NJL.Model.NJL_MESSAGES)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<NJL.Model.NJL_MESSAGES> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<NJL.Model.NJL_MESSAGES> DataTableToList(DataTable dt)
        {
            List<NJL.Model.NJL_MESSAGES> modelList = new List<NJL.Model.NJL_MESSAGES>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                NJL.Model.NJL_MESSAGES model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new NJL.Model.NJL_MESSAGES();
                    model.ID = dt.Rows[n]["ID"].ToString();
                    model.TO_USER_ID = dt.Rows[n]["TO_USER_ID"].ToString();
                    if (dt.Rows[n]["MESSAGE_TYPE"].ToString() != "")
                    {
                        model.MESSAGE_TYPE = int.Parse(dt.Rows[n]["MESSAGE_TYPE"].ToString());
                    }
                    model.MESSAGE_CONTENT = dt.Rows[n]["MESSAGE_CONTENT"].ToString();
                    model.CREATE_USER_NAME = dt.Rows[n]["CREATE_USER_NAME"].ToString();
                    model.CREATE_USER_ID = dt.Rows[n]["CREATE_USER_ID"].ToString();
                    if (dt.Rows[n]["CREATE_DATE_TIME"].ToString() != "")
                    {
                        model.CREATE_DATE_TIME = DateTime.Parse(dt.Rows[n]["CREATE_DATE_TIME"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

